package com.kk.medical_checkitem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kk.medical_checkitem.entity.TCheckitem;
import com.kk.medical_checkitem.service.TCheckitemService;
import com.kk.medical_checkitem.util.QueryPageBean;
import com.kk.medical_checkitem.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yjq
 * @since 2023-02-06
 */
@RestController
@RequestMapping("/tcheckitem")
public class TCheckitemController {
    @Autowired
    private TCheckitemService tCheckitemService;

    @RequestMapping("/findpage")
    public Result findall(@RequestBody QueryPageBean queryPageBean) {
        Page<TCheckitem> info = tCheckitemService.findall(queryPageBean);
        if (info != null) {
            System.out.println("kkkkkkk");
            System.out.println("白敬亭");
            System.out.println("我是你的同桌");
            System.out.println("我是你的同桌2mm");
            System.out.println("我是你的同桌3mm");
            return new Result(true, "分页查询成功", info);
        } else {
            return new Result(false, "查询失败");
        }
    }

    @RequestMapping("/findByid/{id}")
    public Result selectByid(@PathVariable Integer id) {
        TCheckitem byId = tCheckitemService.findById(id);
        if (byId!=null) {
            return new Result(true, "根据id查询成功", byId);
        } else {
            return new Result(false, "根据id查询失败");
        }
    }
    @RequestMapping("/save")
    public Result saveTCheckitem(@RequestBody TCheckitem tCheckitem) {
        int i = tCheckitemService.saveCheckItem(tCheckitem);
        if (i > 0) {
            return new Result(true, "新增成功", i);
        } else {
            return new Result(false, "新增失败");
        }
    }

    @RequestMapping("/del/{id}")
    public Result saveTCheckitem(@PathVariable Integer id) {
        int i = tCheckitemService.deleteCheckItem(id);
        if (i > 0) {
            return new Result(true, "删除成功", i);
        } else {
            return new Result(false, "删除失败");
        }
    }

    @RequestMapping("/update")
    public Result updateTCheckitem(@RequestBody TCheckitem tCheckitem) {
        int i = tCheckitemService.updateCheckItem(tCheckitem);
        if (i > 0) {
            return new Result(true, "修改成功", i);
        } else {
            return new Result(false, "修改失败");
        }
    }
}

